package org.example.controller;

import org.example.Service.OrderService;
import org.example.Service.ShippingInfoService;
import org.example.pojo.Order;
import org.example.pojo.Product;
import org.example.pojo.ShippingInfo;
import org.example.pojo.Status;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;



@Controller
public class ShippingInfoController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private ShippingInfoService shippingInfoService;

    @RequestMapping("/selectShippingInfoByOrderID/{id}")
    public String selectShippingInfoByOrderID(@PathVariable("id") Integer order_id, Model model){
        System.out.println(order_id);
        ShippingInfo shippingInfo=shippingInfoService.selectShippingInfoByOrderID(order_id);
        model.addAttribute("shippingInfo",shippingInfo);
        System.out.println(shippingInfo.getTracking_number());
        return "showTrackNumber";
    }

    @RequestMapping("/selectUserShippingInfoByOrderID/{id}")
    public String selectUserShippingInfoByOrderID(@PathVariable("id") Integer order_id, Model model){
        System.out.println(order_id);
        ShippingInfo shippingInfo=shippingInfoService.selectShippingInfoByOrderID(order_id);
        model.addAttribute("shippingInfo",shippingInfo);
        System.out.println(shippingInfo.getTracking_number());
        return "showUserTrackNumber";
    }


    //跳转到添加快递单号页面
    @RequestMapping("/toInsertShippingInfo/{id}")
    public String toInsertProduct(@PathVariable("id") Integer order_id,Model model) {
        Order order = orderService.selectOrderByOrderIDIng(order_id);
        model.addAttribute("order", order);
        return "insertShippingInfo";
    }
    //添加快递单号
    @RequestMapping("/insertShippingInfo")
    public String insertShippingInfo(Order order,ShippingInfo shippingInfo){
        order.setStatus(Status.已发货);
        orderService.updateOrder(order);
        shippingInfoService.insertShippingInfo(shippingInfo);
        return "shippingInfoFaHuo";
    }
}
